package com.tte.common.designpattern.abstractfactory;

import com.tte.common.designpattern.service.Place;
import com.tte.common.designpattern.service.Shopping;

/**
 * 设计模式-抽象工厂模式
 * 使用 FactoryProducer 来获取 AbstractFactory，通过传递类型信息来获取实体类的对象
 * @Author: DongWH
 */
public class AbstractFactoryDemo {
    public static void main(String[] args) {

        //获取商品工厂
        AbstractFactory shopFactory = FactoryProducer.getFactory("shopping");

        //获取foods
        Shopping sshopFactory1 = shopFactory.getShopping("foods");
        sshopFactory1.view();
        //获取commputer
        Shopping shopFactory2 = shopFactory.getShopping("commputer");
        shopFactory2.view();
        //获取phone
        Shopping shopFactory3 = shopFactory.getShopping("phone");
        shopFactory3.view();

        //获取地区工厂
        AbstractFactory placeFactory = FactoryProducer.getFactory("place");

        //获取颜色为 Red 的对象
        Place placeFactory1 = placeFactory.getPlace("china");
        placeFactory1.getPlace();

        //获取颜色为 Green 的对象
        Place placeFactory2 = placeFactory.getPlace("usa");
        placeFactory2.getPlace();

        //获取颜色为 Blue 的对象
        Place placeFactory3 = placeFactory.getPlace("russial");
        placeFactory3.getPlace();
    }
}
